using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Collections.Generic;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Framework.Config;
using WOODIFramework.Model;

namespace WOODIFramework.UI.Test
{
    /// <summary>
    ///This is a test class for WOODIFramework.Model.Page and is intended
    ///to contain all WOODIFramework.Model.Page Unit Tests
    ///</summary>
    [TestClass()]
    class BuildPages
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestInitialize()]
        public void MyTestInitialize()
        {
            InitActiveRecord();
            RecreateSchema();
        }
        //
        //Use TestCleanup to run code after each test has run
        //
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        

        private void InitActiveRecord()
        {
            XmlConfigurationSource config = new XmlConfigurationSource("NonTestConfig.xml");
            ActiveRecordStarter.Initialize(System.Reflection.Assembly.Load("WOODIFramework.Model"), config);
            
        }

        private void RecreateSchema()
        {
            ActiveRecordStarter.DropSchema();
            ActiveRecordStarter.CreateSchema();
        }

        [TestMethod()]
        public void BuildAllPages()
        {
            BuildBasicPage();
            BuildFormPage();
        }

        [TestMethod()]
        public void BuildBasicPage()
        {
            Page page = BasicPage.NewBasicPage("BasicPage");
            page.NumberRows = 5;
            page.NumberColumns = 2;
            Label label = Label.CreateLabel("Title", "Basic Page");
            label.ColumnPosition = 1;
            label.RowPosition = 1;
            label.Tooltip = "Test tooltip";
            label.Create();
            page.Items.Add(label);

            page.Create();
        }

        [TestMethod()]
        public void BuildFormPage()
        {
            FormPage page = (FormPage)FormPage.NewFormPage("FormPage");
            page.NumberRows = 5;
            page.NumberColumns = 2;
            page.Action = "ProcessFormPage.rails";
            #region Title Label
            Label label = Label.CreateLabel("Title", "Form Page");
            label.ColumnPosition = 0;
            label.RowPosition = 0;
            label.Tooltip = "This is the page title";
            label.Create();
            page.Items.Add(label);
            #endregion

            #region Name Label
            label = Label.CreateLabel("NameLabel", "Name:");
            label.ColumnPosition = 0;
            label.RowPosition = 1;
            label.Tooltip = "Name of item";
            label.Create();
            page.Items.Add(label);
            #endregion

            #region Name Textbox
            TextBox textBox = TextBox.CreateTextBox("NameTextBox", "Kevin McDonnell");
            textBox.ColumnPosition = 1;
            textBox.RowPosition = 1;
            textBox.Tooltip = "Name of the person";
            textBox.Create();
            page.Items.Add(textBox);
            #endregion

            #region Submit Button
            SubmitButton submitButton = SubmitButton.CreateSubmitButton("SubmitButton", "Submit");
            submitButton.ColumnPosition = 1;
            submitButton.RowPosition = 4;
            submitButton.Tooltip = "Submit the form";
            submitButton.Create();
            page.Items.Add(submitButton);
            #endregion
            page.Create();
        }
    }
}
